<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="__PLUGIN__/layui/css/layui.css" rel="stylesheet" />
    <style>
        .verify{
            display: block;
            height: 36px;
            line-height: 36px;
            border: 1px solid #e6e6e6;
            background-color: #fff;
            border-radius: 2px;
            padding-left: 10px;
            width: 160px;
        }
    </style>
</head>
<body>
<form class='layui-form' action='' method="post" >
    <div class='layui-form-item'>
        <label class='layui-form-label'>账号</label>
        <div class='layui-input-inline pm-login-input'>
            <input type='text' name='username' lay-verify='account' placeholder='请输入账号'  autocomplete='off' class='layui-input' id="userName">
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>密码</label>
        <div class='layui-input-inline pm-login-input'>
            <input type='password' name='userpwd' lay-verify='passWord' placeholder='请输入密码'  autocomplete='off' class='layui-input' id="userPwd">
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>人机验证</label>
        <div class='layui-input-block'>
            <input type='text' name='yzm' placeholder='请输入密码' lay-verify='passWord'  value='' autocomplete='off' class='verify'style="float: left">
            <img id="verify_img" class="pull-right" src="{:captcha_src()}" alt="验证码"  onclick="refreshVerify()" style="float: right">
        </div>
    </div>
    <div class='layui-form-item' style='margin-top:25px;margin-bottom:0;'>
        <div class='layui-input-block'>
            <input type="button" class="layui-btn" id="Submit" style='width:100%;' lay-submit='' lay-filter='login' value="立即登陆">
        </div>
    </div>
</form>
</body>
<script src="__PLUGIN__/jquery/jquery-2.2.4.js"></script>
<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
<script>
    // 刷新验证码
    function refreshVerify() {
        var ts = Date.parse(new Date())/1000;
        var img = document.getElementById('verify_img');
        img.src = "/index.php/captcha?id="+ts;
    }
    $('#Submit').click(function(){
        if($('#userName').val() === ''){
            layer.msg('用户名不能为空',{icon:5},refreshVerify())
        }else if($('#userPwd').val() === ''){
            layer.msg('密码不能为空',{icon:5},refreshVerify())
        }else{
            var formData=$('form').serialize();
            $.ajax({
                type:"post",
                url:"{:url('login_check')}",
                data:formData,
                success:function (data) {
                    if (data ==1){
                        layer.msg('登陆成功，正在跳转......', { icon: 6 });
                        setTimeout(function () {
                            window.parent.location.href="/admin";
                        }, 1000);
                    }else {
                        layer.msg(data,{icon:5},refreshVerify())
                    }

                }
            })
        }

    });
</script>
</html>